{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "time.struct_time(tm_year=2024, tm_mon=7, tm_mday=26, tm_hour=9, tm_min=45, tm_sec=17, tm_wday=4, tm_yday=208, tm_isdst=0)\n",
      "time.struct_time(tm_year=2024, tm_mon=7, tm_mday=26, tm_hour=1, tm_min=45, tm_sec=17, tm_wday=4, tm_yday=208, tm_isdst=0)\n",
      "1721958317.3604367\n",
      "2024-07-26 09:45:17\n",
      "2024-07-26 09:45:17\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "# 三种时间\n",
    "# 1、结构化时间\n",
    "print(time.localtime())\n",
    "print(time.gmtime())\n",
    "# 2、时间戳\n",
    "print(time.time())\n",
    "# 3、格式化时间字符串\n",
    "print(time.strftime(\"%F %T\", time.localtime()))\n",
    "print(time.strftime(\"%Y-%m-%d %H:%M:%S\", time.localtime()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1721958009.0\n"
     ]
    }
   ],
   "source": [
    "# time1 = 1721958009\n",
    "# time2 = time.localtime(time1)\n",
    "# time3 = time.strftime(\"%F %T\", time2)\n",
    "# print(time3)\n",
    "\n",
    "# time1 = \"2024-07-26 09:40:09\"\n",
    "# time2 = time.strptime(time1, \"%Y-%m-%d %H:%M:%S\")\n",
    "# time3 = time.mktime(time2)\n",
    "# print(time3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "import shutil\n",
    "# # 拷贝\n",
    "# r = shutil.copyfile(\"hello/world\", \"hello/world1\")\n",
    "# print(r)\n",
    "# # 在拷贝时，保留文件的权限\n",
    "# shutil.copy2(\"hello/world\", \"hello/world2\")\n",
    "# 递归拷贝\n",
    "# shutil.copytree(\"./hello\", \"./hello2\", ignore=shutil.ignore_patterns(\"world*\"))\n",
    "# 递归删除\n",
    "shutil.rmtree(\"./hello1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'hello1'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shutil.move(\"hello\",\"hello1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('bztar', \"bzip2'ed tar-file\"), ('gztar', \"gzip'ed tar-file\"), ('tar', 'uncompressed tar file'), ('xztar', \"xz'ed tar-file\"), ('zip', 'ZIP file')]\n"
     ]
    }
   ],
   "source": [
    "# 打包类型\n",
    "print(shutil.get_archive_formats())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{}"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import yagmail\n",
    "\n",
    "yag = yagmail.SMTP(user=\"newrain_wang@163.com\",\n",
    "             password=\"MGISJFAQMJYWMMZX\",\n",
    "             host=\"smtp.163.com\",\n",
    "             port=465,\n",
    "             smtp_ssl=True)\n",
    "yag.send(to=\"newrain_wang@163.com\", subject=\"简单邮件\", contents=\"hello\", attachments=\"修罗武神.txt\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "发送字节数: 5705.8203125 接收字节数: 2494.1503906253755"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[5], line 9\u001b[0m\n\u001b[0;32m      7\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[0;32m      8\u001b[0m     oout, oin \u001b[38;5;241m=\u001b[39m func()\n\u001b[1;32m----> 9\u001b[0m     time\u001b[38;5;241m.\u001b[39msleep(\u001b[38;5;241m1\u001b[39m)\n\u001b[0;32m     10\u001b[0m     out, sin  \u001b[38;5;241m=\u001b[39m func()\n\u001b[0;32m     11\u001b[0m     \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\r\u001b[39;00m\u001b[38;5;124m发送字节数: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m(out\u001b[38;5;250m \u001b[39m\u001b[38;5;241m-\u001b[39m\u001b[38;5;250m \u001b[39moout)\u001b[38;5;250m \u001b[39m\u001b[38;5;241m/\u001b[39m\u001b[38;5;250m \u001b[39m\u001b[38;5;241m1024\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m 接收字节数: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m(sin\u001b[38;5;250m \u001b[39m\u001b[38;5;241m-\u001b[39m\u001b[38;5;250m \u001b[39moin)\u001b[38;5;250m \u001b[39m\u001b[38;5;241m/\u001b[39m\u001b[38;5;250m \u001b[39m\u001b[38;5;241m1024\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, end\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "import psutil, time\n",
    "def func():\n",
    "    net_io = psutil.net_io_counters()\n",
    "    old_out = net_io.bytes_sent\n",
    "    old_in = net_io.bytes_recv\n",
    "    return old_out,old_in\n",
    "while True:\n",
    "    oout, oin = func()\n",
    "    time.sleep(1)\n",
    "    out, sin  = func()\n",
    "    print(f\"\\r发送字节数: {(out - oout) / 1024} 接收字节数: {(sin - oin) / 1024}\", end=\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
